#import "ALInfoViewController.h"
#import "NSObject+BlockObservation.h"


@implementation ALInfoViewController

@synthesize emptyInfoView;
@synthesize eventInfoView;
@synthesize timelineInfoView;
@synthesize chartInfoView;


-(void)awakeFromNib {
    AMBlockTask modeTask = ^(id object, NSDictionary *change) {
        ALDetailMode currentMode = (ALDetailMode)[[NSUserDefaults standardUserDefaults] integerForKey:ALModeSelection];
        [self switchToMode:currentMode];
    };
    modeTask(nil, nil);
    NSString *modeKey = [NSString stringWithFormat:@"values.%@", ALModeSelection];
    [[NSUserDefaultsController sharedUserDefaultsController] addObserverForKeyPath:modeKey task:modeTask];
}

-(void)switchToMode:(ALDetailMode)mode {
    NSView *modeInfoView = nil;
    switch (mode) {
        case ALModeEvent:
            modeInfoView = [self eventInfoView];
            break;
        case ALModeTimeline:
            modeInfoView = [self timelineInfoView];
            break;
        case ALModeChart:
            modeInfoView = [self chartInfoView];
            break;
        default:
            modeInfoView = [self emptyInfoView];
    }
    NSRect viewRect = [[self view] bounds];
    [modeInfoView setFrame:viewRect];
    [[self view] setSubviews:[NSArray arrayWithObject:modeInfoView]];
}

@end
